/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.jclip.examples.helloworld;


import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.JMenu;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import org.jclip.runtime.JavaClientPage;
import org.jclip.runtime.ValidationError;

import java.awt.Color;
import javax.swing.GroupLayout.Alignment;
import javax.swing.GroupLayout;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import java.awt.Font;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Dimension;
import java.awt.Component;
/**
 *
 * @author kissmyirish
 */
public class DoodleScheduleEvent extends JavaClientPage {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	protected HashMap<String,Object> hm = new HashMap<String,Object>();
	protected JMenu menu = new JMenu("Schedule Event");
	protected String pageTitle = "MyDoodle.com Schedule Event";
	private ArrayList<ValidationError> warnings = new ArrayList<ValidationError>();

    /**
     * Creates new form DoodleScheduleEvent
     */
    public DoodleScheduleEvent(HashMap<String,Object> hm) {
    	super(hm);
    	this.hm=hm;
    	 initComponents();
     }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jPanel1.setAlignmentX(Component.RIGHT_ALIGNMENT);
        upperPanel = new javax.swing.JPanel();
        doodle = new javax.swing.JLabel();
        signIN = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        setBackground(new Color(255, 255, 255));
        setForeground(new java.awt.Color(215, 234, 253));
        setPreferredSize(new Dimension(833, 767));

        jPanel1.setBackground(new Color(255, 255, 255));

        upperPanel.setBackground(new java.awt.Color(255, 255, 255));

        doodle.setFont(new java.awt.Font("Arial Black", 1, 36)); // NOI18N
        doodle.setForeground(new java.awt.Color(51, 102, 255));
        doodle.setText("MyDoodle");

        signIN.setBackground(new java.awt.Color(255, 255, 255));
        signIN.setForeground(new java.awt.Color(0, 102, 204));
        signIN.setText("Sign in");

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel4.setText("1. General >");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel5.setForeground(new java.awt.Color(102, 102, 102));
        jLabel5.setText("2. Time proposals >");

        jLabel6.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel6.setForeground(new java.awt.Color(102, 102, 102));
        jLabel6.setText("3. Settings >");

        jLabel7.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLabel7.setForeground(new java.awt.Color(102, 102, 102));
        jLabel7.setText("4. Invite");

        jLabel8.setFont(new java.awt.Font("Tahoma", 0, 36)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(0, 102, 204));
        jLabel8.setText("Schedule an event");

        javax.swing.GroupLayout upperPanelLayout = new javax.swing.GroupLayout(upperPanel);
        upperPanelLayout.setHorizontalGroup(
        	upperPanelLayout.createParallelGroup(Alignment.LEADING)
        		.addGroup(upperPanelLayout.createSequentialGroup()
        			.addGap(20)
        			.addGroup(upperPanelLayout.createParallelGroup(Alignment.LEADING)
        				.addGroup(upperPanelLayout.createSequentialGroup()
        					.addGroup(upperPanelLayout.createParallelGroup(Alignment.LEADING)
        						.addComponent(jLabel8)
        						.addGroup(upperPanelLayout.createSequentialGroup()
        							.addComponent(jLabel4)
        							.addGap(18)
        							.addComponent(jLabel5)
        							.addGap(18)
        							.addComponent(jLabel6)
        							.addGap(18)
        							.addComponent(jLabel7)))
        					.addContainerGap())
        				.addGroup(upperPanelLayout.createSequentialGroup()
        					.addComponent(doodle)
        					.addGap(444)
        					.addComponent(signIN, GroupLayout.DEFAULT_SIZE, 102, Short.MAX_VALUE)
        					.addGap(40))))
        );
        upperPanelLayout.setVerticalGroup(
        	upperPanelLayout.createParallelGroup(Alignment.LEADING)
        		.addGroup(upperPanelLayout.createSequentialGroup()
        			.addGap(24)
        			.addGroup(upperPanelLayout.createParallelGroup(Alignment.LEADING)
        				.addComponent(signIN)
        				.addGroup(upperPanelLayout.createSequentialGroup()
        					.addComponent(doodle, GroupLayout.PREFERRED_SIZE, 40, GroupLayout.PREFERRED_SIZE)
        					.addGap(18)
        					.addComponent(jLabel8)
        					.addGap(18)
        					.addGroup(upperPanelLayout.createParallelGroup(Alignment.BASELINE)
        						.addComponent(jLabel4)
        						.addComponent(jLabel5)
        						.addComponent(jLabel6)
        						.addComponent(jLabel7))))
        			.addContainerGap(15, Short.MAX_VALUE))
        );
        upperPanel.setLayout(upperPanelLayout);
        
        panel = new JPanel();
        panel.setBackground(new Color(215,234,253));

        panel.setLayout(null);
        
        JLabel label = new JLabel();
        label.setBounds(105, 16, 0, 0);
        panel.add(label);
        
      
        final JLabel label_1 = new JLabel();
        label_1.setBounds(109, 323, 99, 22);
        label_1.setText("Your name");
        label_1.setFont(new Font("Tahoma", Font.BOLD, 18));
        panel.add(label_1);
        
        textField_1 = new JTextField();
        textField_1.setBounds(105, 178, 528, 134);
        textField_1.getDocument().addDocumentListener(new DocumentListener() {

            
        	public void changedUpdate(DocumentEvent evt){
                String text = textField_1.getText();
                hm.put("description",text);
        	}
        	
        	public void insertUpdate(DocumentEvent evt){
                String text = textField_1.getText();
                hm.put("description",text);
        	}
        	
        	public void removeUpdate(DocumentEvent evt){
        	}
        });
        panel.add(textField_1);
        
        JLabel label_2 = new JLabel();
        label_2.setBounds(105, 145, 103, 22);
        label_2.setText("Description");
        label_2.setFont(new Font("Tahoma", Font.BOLD, 18));
        panel.add(label_2);
        
        JLabel label_3 = new JLabel();
        label_3.setBounds(218, 152, 68, 14);
        label_3.setText("(optional)");
        label_3.setForeground(new Color(102, 102, 102));
        panel.add(label_3);
        
        JLabel label_4 = new JLabel();
        label_4.setBounds(105, 77, 77, 22);
        label_4.setText("Location");
        label_4.setFont(new Font("Tahoma", Font.BOLD, 18));
        panel.add(label_4);
        
        JLabel label_5 = new JLabel();
        label_5.setBounds(218, 84, 68, 14);
        label_5.setText("(optional)");
        label_5.setForeground(new Color(102, 102, 102));
        panel.add(label_5);
        
        final JLabel label_6 = new JLabel();
        label_6.setBounds(105, 15, 39, 22);
        label_6.setText("Title");
        label_6.setFont(new Font("Tahoma", Font.BOLD, 18));
         panel.add(label_6);
         
         textField = new JTextField();
         textField.setBounds(105, 46, 333, 20);
         textField.getDocument().addDocumentListener(new DocumentListener(){

         	
         	public void changedUpdate(DocumentEvent evt){

         	}
         	
         	public void insertUpdate(DocumentEvent evt){
         		label_6.setForeground(Color.BLACK);
         		String text = textField.getText();
        		hm.put("title",text);
         	}
         	
         	public void removeUpdate(DocumentEvent evt){
         		label_6.setForeground(Color.BLACK);
         		String text = textField.getText();
        		hm.put("title",text);
         	}
         });
         panel.add(textField);
        
        textField_2 = new JTextField();
        textField_2.setBounds(105, 110, 333, 20);
        textField_2.setText("e.g., 1600 Amphithatre Parkway, Mountain View");
        textField_2.setForeground(new Color(102, 102, 102));
        textField_2.getDocument().addDocumentListener(new DocumentListener() {
        	public void changedUpdate(DocumentEvent evt){
        		String text = textField_2.getText();
        		hm.put("location",text);
        	}
        	
        	public void insertUpdate(DocumentEvent evt){
        		String text = textField_2.getText();
        		hm.put("location",text);
        	}
        	
        	public void removeUpdate(DocumentEvent evt){
        		String text = textField_2.getText();
        		hm.put("location",text);
        	}
        });
        panel.add(textField_2);
        
        textField_3 = new JTextField();
        textField_3.setBounds(105, 356, 333, 20);
        textField_3.getDocument().addDocumentListener(new DocumentListener() {

        	public void changedUpdate(DocumentEvent evt){

        	}
        	
        	public void insertUpdate(DocumentEvent evt){
        		label_1.setForeground(Color.BLACK);
        		String text = textField_3.getText();
        		hm.put("name",text);
        	}
        	
        	public void removeUpdate(DocumentEvent evt){
        		label_1.setForeground(Color.BLACK);
        		String text = textField_3.getText();
        		hm.put("name",text);
        	}
        });
        panel.add(textField_3);
        
        JLabel label_7 = new JLabel();
        label_7.setBounds(105, 387, 132, 22);
        label_7.setText("E-mail address");
        label_7.setFont(new Font("Tahoma", Font.BOLD, 18));
        panel.add(label_7);
        
        JLabel label_8 = new JLabel();
        label_8.setBounds(247, 394, 121, 14);
        label_8.setText("(recommended)");
        label_8.setForeground(new Color(102, 102, 102));
        panel.add(label_8);
        
        JLabel label_9 = new JLabel();
        label_9.setBounds(105, 451, 285, 15);
        label_9.setText("If you supply an e-mail address, you will receive the ");
        label_9.setForeground(new Color(102, 102, 102));
        label_9.setFont(new Font("Tahoma", Font.PLAIN, 12));
        panel.add(label_9);
        
        textField_4 = new JTextField();
        textField_4.setBounds(105, 420, 333, 20);
        textField_4.getDocument().addDocumentListener(new DocumentListener() {
        	public void changedUpdate(DocumentEvent evt){
        		String text = textField_4.getText();
        		hm.put("e-mail address",text);
        	}
        	
        	public void insertUpdate(DocumentEvent evt){
        		String text = textField_4.getText();
        		hm.put("e-mail address",text);
        	}
        	
        	public void removeUpdate(DocumentEvent evt){
        		String text = textField_4.getText();
        		hm.put("e-mail address",text);
        	}
        });
        panel.add(textField_4);
        
        JLabel label_10 = new JLabel();
        label_10.setBounds(107, 462, 261, 15);
        label_10.setText("link to administer your poll. This will not open a ");
        label_10.setForeground(new Color(102, 102, 102));
        label_10.setFont(new Font("Tahoma", Font.PLAIN, 12));
        panel.add(label_10);
        
        JLabel label_11 = new JLabel();
        label_11.setBounds(107, 477, 179, 15);
        label_11.setText("MyDoodle account automatically.");
        label_11.setForeground(new Color(102, 102, 102));
        label_11.setFont(new Font("Tahoma", Font.PLAIN, 12));
        panel.add(label_11);
        
        JButton button = new JButton();
        button.setBounds(105, 524, 68, 23);
        button.setText("Back");
        button.setEnabled(false);
        button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
            	browser.go("http://localhost//org.jclip.examples.helloworld//bin//#org.jclip.examples.helloworld.DoodlePanel2", hm);
            }
        });
        panel.add(button);
        
        JButton button_1 = new JButton();
        button_1.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent arg0) {
            	if(hm.containsKey("name")&&hm.containsKey("title")){
            		if(!hm.get("name").equals("")&&!hm.get("title").equals("")){
            	browser.go("http://localhost//org.jclip.examples.helloworld//bin//#org.jclip.examples.helloworld.DoodleDays", hm);
            		}
            		else{
            			
                		if(hm.get("name").equals("")){
                			ValidationError error = new ValidationError();
                			error.setMessage("You need to enter a name");
                			error.setComponent(label_1);
                			error.setWarning(true);
                			error.setDescription("You have not entered a valid name");
                			warnings.add(error);               			
                		}
                		if(hm.get("title").equals("")){
                			ValidationError error = new ValidationError("You need to enter a title", label_6, true, "You have" +
                					"not entered a valid title");
                			warnings.add(error);
                		}
                		browser.reportErrors(warnings);
                		warnings.clear();
            		}
            	} else{
            		if(!hm.containsKey("name")){
            			ValidationError error = new ValidationError();
            			error.setMessage("You need to enter a name");
            			error.setComponent(label_1);
            			error.setWarning(true);
            			error.setDescription("You have not entered a valid name");
            			warnings.add(error);  
            		}
            		if(!hm.containsKey("title")){
            			ValidationError error = new ValidationError("You need to enter a title", label_6, true, "You have" +
            					"not entered a valid title");
            			warnings.add(error);
            		}
            		browser.reportErrors(warnings);
            		warnings.clear();
            	}
        	}
        });
        button_1.setBounds(183, 524, 68, 23);
        button_1.setText("Next");
        panel.add(button_1);
        
        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1Layout.setHorizontalGroup(
        	jPanel1Layout.createParallelGroup(Alignment.LEADING)
        		.addComponent(upperPanel, GroupLayout.PREFERRED_SIZE, 683, Short.MAX_VALUE)
        		.addGroup(jPanel1Layout.createSequentialGroup()
        			.addGap(10)
        			.addComponent(panel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        			.addGap(10))
        );
        jPanel1Layout.setVerticalGroup(
        	jPanel1Layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(jPanel1Layout.createSequentialGroup()
        			.addComponent(upperPanel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
        			.addPreferredGap(ComponentPlacement.RELATED)
        			.addComponent(panel, GroupLayout.PREFERRED_SIZE, 615, GroupLayout.PREFERRED_SIZE)
        			.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1.setLayout(jPanel1Layout);

        jScrollPane1.setViewportView(jPanel1);
        jScrollPane1.getVerticalScrollBar().setUnitIncrement(16);
        
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        layout.setHorizontalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 847, Short.MAX_VALUE)
        			.addGap(0))
        );
        layout.setVerticalGroup(
        	layout.createParallelGroup(Alignment.LEADING)
        		.addGroup(layout.createSequentialGroup()
        			.addComponent(jScrollPane1, GroupLayout.DEFAULT_SIZE, 821, Short.MAX_VALUE)
        			.addGap(0))
        );
        this.setLayout(layout);
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jTextField1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jTextField1ActionPerformed

    private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_backButtonActionPerformed

    private void nextButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_nextButtonActionPerformed
        // TODO add your handling code here:
    	browser.go("http://localhost/org.jclip.examples.helloworld/bin/#org.jclip.examples.helloworld.HelloWorld2Page", hm);
    }//GEN-LAST:event_nextButtonActionPerformed
    
    public JMenu getMenus()
    {
    	return menu;
    }
    
    public String getTitle()
    {
    	return pageTitle;
    }

    private javax.swing.JLabel doodle;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JLabel signIN;
    private javax.swing.JPanel upperPanel;
    private JPanel panel;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JTextField textField_3;
    private JTextField textField_4;
}
